package pkg.filter;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.Query;
import java.util.ArrayList;
import java.util.List;
import pkg.dao.Filter;
import pkg.entity.Auction;
import pkg.entity.Bid;
import pkg.entity.User;

public class BidFilter extends Filter {

    private Auction auction;
    private User user;

    @Override
    public List getElements(Objectify ofy) {
        Query<Bid> query = ofy.query(Bid.class);
        if (auction != null) {
            query.filter("auctionKey = ", auction.getPrimaryKey());
            query.order("-timestamp");
        }
        if (user != null) {
            query.filter("userKey = ", user.getPrimaryKey());
            query.order("-timestamp");
        }
        query.limit(getNumRows());
        List<Bid> entities = new ArrayList<Bid>();
        for (Bid e : query) {
            entities.add(e);
        }
        return entities;
    }

    @Override
    public int getCount(Objectify ofy) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setSimple(String filterText) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public Auction getAuction() {
        return auction;
    }

    public void setAuction(Auction auction) {
        this.auction = auction;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
